using System;
using System.Reflection;
using System.Reflection.Emit;

namespace RaisingStudio.SmallBasicCompiler.Expressions
{
	[Serializable]
	public class IdentifierExpression : Expression
	{
		public TokenInfo Identifier
		{
			get;
			set;
		}
		public override void AddSymbols(SymbolTable symbolTable)
		{
			symbolTable.AddVariable(this.Identifier);
		}
		public void AddSymbolInitialization(SymbolTable symbolTable)
		{
			symbolTable.AddVariableInitialization(this.Identifier);
		}
		public override void EmitIL(CodeGenScope scope)
		{
			FieldInfo field = scope.Fields[this.Identifier.NormalizedText];
			scope.ILGenerator.Emit(OpCodes.Ldsfld, field);
		}
		public override string ToString()
		{
			return this.Identifier.Text;
		}
	}
}
